import 'dart:io';

import 'package:get/get.dart';

import '../../utils/toast_utils.dart';
import 'main_state.dart';

class MainLogic extends GetxController {
  final MainState state = MainState();

  DateTime? lastPopTime;

  void onPopInvoked() {
    if (lastPopTime == null || DateTime.now().difference(lastPopTime!) > Duration(seconds: 1)) {
      lastPopTime = DateTime.now();
      toast.show("再按一次退出");
    } else {
      lastPopTime = DateTime.now();
      // 退出app
      exit(0);
    }
  }

  void onItemSelected(int index) {
    state.currentIndex = index;
    update();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }
}
